<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"  
    xmlns:h="http://java.sun.com/jsf/html"  
    xmlns:f="http://java.sun.com/jsf/core"  
    xmlns:p="http://primefaces.org/ui"
    xmlns:ui="http://java.sun.com/jsf/facelets">

	<ui:decorate template="/template/template.xhtml">
		<ui:define name="centro">
				<h:form id="form">				
				<p:dataTable id="dataTable" var="associacao" value="#{associacaoBean.listaAssociacoes}"
					emptyMessage="Nenhuma Associação encontrada" paginator="true" rows="10">			       
			        <f:facet name="header">  
			            Lista de Associações
			        </f:facet>
			  
			  		<p:column headerText="Entidade" sortBy="#{associacao.entidade.nome}">  
			            <h:outputText value="#{associacao.entidade.nome}" />  
			        </p:column>
			  
			        <p:column headerText="Data" sortBy="#{associacao.data}">  
			            <h:outputText value="#{associacao.data}">
			            	<f:convertDateTime pattern="dd/MM/yyyy"/>
			            </h:outputText>
			        </p:column>
			        
			        <p:column headerText="Detalhes" styleClass="botaoDentroDaTabela">
			            <p:commandButton onclick="PF('associacaoDialog').show()" id="detalhes" update=":#{p:component('panelGrid')}"
            icon="ui-icon-search" title="Detalhes">
            				<f:setPropertyActionListener value="#{associacao}" target="#{associacaoBean.associacao}" />
            			</p:commandButton>
			        </p:column>
			   
			        <p:column headerText="Alterar" styleClass="botaoDentroDaTabela">
			            <p:commandButton action="#{associacaoBean.preparaAlterarAssociacao}" ajax="false" id="alterar"  
            icon="ui-icon-document" title="Alterar">
            				<f:setPropertyActionListener value="#{associacao}" target="#{associacaoBean.associacao}" />
            			</p:commandButton>
			        </p:column>
					
					<p:column headerText="Excluir" styleClass="botaoDentroDaTabela">  
						<p:commandButton action="#{associacaoBean.excluirAssociacao}" update="dataTable" id="excluir"
							icon="ui-icon-trash" title="Excluir">
							<p:confirm header="Confirmação" message="Você tem certeza que deseja excluir a Associação?"
								icon="ui-icon-alert" />
							<f:setPropertyActionListener value="#{associacao}" target="#{associacaoBean.associacao}" />
						</p:commandButton>

						<p:confirmDialog global="true" showEffect="fade"
							hideEffect="explode">
							<p:commandButton value="Yes" type="button"
								styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
							<p:commandButton value="No" type="button"
								styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
						</p:confirmDialog>
					</p:column>
			  
			        <f:facet name="footer">  
			            Existem no total #{associacaoBean.listaAssociacoes.size()} associações.  
			        </f:facet>
			  
			    </p:dataTable>
			    
			    <p:dialog header="Detalhes" widgetVar="associacaoDialog" resizable="false"
					showEffect="clip" hideEffect="fold" id="dial">

				<h:panelGrid id="panelGrid" columns="2" cellpadding="4">

					<h:outputText value="Entidade:" />
					<h:outputText value="#{associacaoBean.associacao.entidade.nome}"
						style="font-weight:bold" />

					<h:outputText value="Data:" />
					<h:outputText value="#{associacaoBean.associacao.data}"
						style="font-weight:bold">
						<f:convertDateTime pattern="dd/MM/yyyy" timeZone="GMT-03:00"/>
					</h:outputText>					
				</h:panelGrid>
			</p:dialog>

				<p:commandButton id="voltar" ajax="false" value="Voltar" action="index"/>
				<p:commandButton id="incluirAssociacao" ajax="false" value="Incluir" action="#{associacaoBean.preparaIncluirAssociacao}"/>
			</h:form>
		</ui:define>
	</ui:decorate>
</html>